﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using My_TV_Manager.Model;
using My_TV_Manager.View.MenuButton;
using My_TV_Manager.View.ContentPanel;

namespace My_TV_Manager.View.MenuBar
{
    [System.ComponentModel.DesignerCategory("")]

    public class InnerMenuBar : TabbedMenuBar
    {
        #region Private Data

        private InnerTabbedContainer parent;
        private Color defaultColor;

        #endregion

        #region Properties

        public override Size ContainerSize
        {
            get { return this.Size; }
            set
            {
                this.Size = value;
                int remainingPixels = this.Width;
                for (int i = 0; i < buttons.Count; i++)
                {
                    buttons[i].Size = new Size(remainingPixels / (buttons.Count - i), 
                                               this.Height);
                    remainingPixels -= buttons[i].Width;
                }
            }
        }

        public Color DefaultColor
        {
            get { return defaultColor; }
            set { defaultColor = value; }
        }

        #endregion

        #region Constructors

        public InnerMenuBar(InnerTabbedContainer parent, Size size, List<string> buttonText, int color) 
            : base(size)
        {
            // Use the data parameters
            this.parent = parent;
            this.defaultColor = Settings.Colors.Get(color);

            int remainingPixels = this.Width;
            for (int i = 0; i < buttonText.Count; i++)
            {
                // Format each button specifically
                buttons.Add(new InnerTabbedButton());
                buttons[i].Text = buttonText[i];
                buttons[i].Name = "Sub Menu Option " + i;
                buttons[i].ForeColor = defaultColor;
                buttons[i].Size = new Size(remainingPixels / (buttonText.Count - i), 
                                           this.Height);
                remainingPixels -= buttons[i].Width;

                // Add new behavior for button events
                buttons[i].Click += new EventHandler(MenuOptionClick);

                this.Controls.Add(buttons[i]);
            }

            // Select the starting content panel
            selected = 0;
            buttons[selected].PerformClick();
        }

        #endregion

        #region Functions

        protected override void MenuOptionClick(object sender, EventArgs e)
        {
            InnerTabbedButton button = (InnerTabbedButton)sender;

            // Deselect the previously selected option
            buttons[selected].BackColor = Color.White;
            buttons[selected].ForeColor = defaultColor;

            // Change the selected option and update the button and panel
            selected = int.Parse(button.Name.Substring(button.Name.Length - 1));
            buttons[selected].BackColor = defaultColor;
            buttons[selected].ForeColor = Color.Black;

            // Change the content panel in the split container
            parent.ChangeContentPanel(selected);
        }

        #endregion
    }
}
